﻿using System;

using System.Collections.Generic;
using System.Text;
using Silvermoon.Shapes;
using Silvermoon.OpenGL;

namespace Silvermoon.Controls.Sys
{
    internal class HardwareKeyPanel : ChromeControl
    {
        private StringShape left, right;
        private bool landscape = false;

        public HardwareKeyPanel()
            : base()
        {
            left = new StringShape { Text = "Back", FontScale = 0.5f, Alignment = Alignment.Center, LineAlignment = Alignment.Near };
            right = new StringShape { Text = "Home", FontScale = 0.5f, Alignment = Alignment.Center, LineAlignment = Alignment.Near };

            Shapes.AddRange(left, right);
            TextColor = System.Drawing.Color.White;
            IsHitTestVisible = false;
            Opacity = 128;
        }


        public bool Landscape
        {
            get
            {
                return landscape;
            }
            set
            {
                if (landscape != value)
                {
                    landscape = value;
                    Invalidate(InvalidationFlag.Layout);
                }
            }
        }

        private static Transformation[] rotation = new Transformation[] { new RotateTransform { Angle = -90, Axis = RotateAxis.ZAxis, OrigX = -1f, OrigY = -1f } };


        //protected override Shape CreateDefaultBackground()
        //{
        //    return System.Drawing.Color.Black;
        //}


        protected override void OnLayout()
        {
            if (CheckFlag(InvalidationFlag.Size | InvalidationFlag.Layout))
            {
                if (!landscape)
                {
                    int w = Width / 3;
                    int h = Height;
                    left.Transformations = null;
                    right.Transformations = null;
                    left.Bounds = Control.ScaledRect(0, 0, w, h);
                    right.Bounds = Control.ScaledRect(Width - w, 0, w, h);

                }
                else
                {
                    int w = Width;
                    int h = Height / 3;
                    left.Transformations = rotation;
                    right.Transformations = rotation;
                    left.Bounds = Control.ScaledRect(0, Height, h, w);
                    right.Bounds = Control.ScaledRect(0, h, h, w);
                }

            }
            base.OnLayout();
        }
    }
}
